 <%@page import="dao.TauDAO"%>
<%@page import="dto.Tau"%>
<%@page import="dao.LoaiToaTauDAO"%>
<%@page import="dto.LoaiToaTau"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.util.List"%>
<%@page import="dto.ToaTau"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Quản Lý Toa Tàu</title>
        <link href="css/tablestyle.css" type="text/css" rel="stylesheet" />
        <script language="javascript">
            function CheckAllQT(value)
            {
                var checks = document.getElementsByName('delete');
                var boxlength = checks.length;
                if(value == true)
                {
                    for(i=0; i< boxlength;i++)
                    {
                         checks[i].checked = true;
                    }
                }
                else
                {       
                    for(i=0; i< boxlength;i++)
                    {
                        checks[i].checked = false;
                    }
                }
            }
            function Confirm_Del()
            {
                if(confirm("Bạn có chắc muốn xóa không?") == true){
                    return true;
                }else{
                    return false;
                }
            }
            
            function submitWithHref(obj) {
                var theHref = obj.href;
                document.frmToaTau.action = theHref;
                document.frmToaTau.submit();
             }
        </script>
        
        
        <link href="css/jquery-ui.css" type="text/css" rel="stylesheet"/>
        <script src="js/jquery-1.9.1.js" type="text/javascript"></script>
        <script src="js/jquery-ui.js" type="text/javascript"></script>
      
    </head>
    <body>
       <%-- 
        <%
            if(session.getAttribute("USERNAME")==null){
                response.sendRedirect("Login");
            }else{
        %> --%>
       <% try { %>
        
        <div id="container">
            <%@include file="header.jsp" %>
        
        <div id="content">
        
            <%@include file="menu.jsp" %>
            
            <div id="contentpage">

            <form action="ToaTau" method="post" name="frmToaTau">
            <div id="titledata">
                <h>Tàu</h>
                <div class="titleaction"><a class="btninsert" href="ToaTau?action=insert">Insert</a>
                    <input class="btndelete" name="action" type="submit" value="Delete" onclick="return Confirm_Del();" />
                </div>
            </div>
            <div id="contentdata">
            <% 
                List<ToaTau> dsnd = (List<ToaTau>) request.getAttribute("dsnd");
            %>

            <table class="tbdata">
                <tr class="title">
                    <td><input type="checkbox" name="checkall" onclick="CheckAllQT(checkall.checked);" /></td>
                    <td>Mã Toa Tàu</td>
                    <td>STT</td>
                    <td>Mã Tàu</td>
                    <td>Số lượng ghế</td> 
                    <td>Trạng thái</td>
                    <td>Loại toa tàu</td>
                    <td>Action</td>
                </tr>
               
                <%
               // int sotrang = (Integer)request.getAttribute("sotrang"); 
                for(int i =0; i < dsnd.size(); i++){
                %>
                <% if(i%2==0){ %>
                <tr class="even"> 
                    <% }else { %>
                <tr class="odd">
                   <% } %>
                    <td><input type="checkbox" name="delete" value="<%= dsnd.get(i).getMatau()%>" /></td>
                    <td><%= dsnd.get(i).getMatoatau()%></td>
                    <td><%= dsnd.get(i).getStttoa()%></td>
                       <td>  <% List<Tau> dstau_toatau = (List<Tau>) request.getAttribute("dstau_toatau"); %>
                        <% 
                            if(dstau_toatau.get(i).getMatau()!= 0){
                            String  tentau ="";
                            Integer matau = dstau_toatau.get(i).getMatau();
                            tentau = TauDAO.LayThongTinTau(matau.toString()).getTendoantau();
                            out.print(tentau);
                            }
                        %> 
                    </td> 
                    <td><%= dsnd.get(i).getSoluongghe()%></td> 
                    <td><% if(dsnd.get(i).getTrangthai() == 1){
                            out.print("Hiện");
                        } else{
                            out.print("Ẩn");
                        } %>
                    </td>
                    
                    
                           
                    <td>  <% List<LoaiToaTau> dslnd = (List<LoaiToaTau>) request.getAttribute("dslnd"); %>
                        <% 
                            if(dsnd.get(i).getMaloaitoatau()!= 0){
                            String  tenloainguoidung ="";
                            tenloainguoidung = LoaiToaTauDAO.LayThongTinLoaiToaTau(dsnd.get(i).getMaloaitoatau()).getTenloaitoatau();
                            out.print(tenloainguoidung);
                            }
                        %> 
                    </td>
                    <td>
                        <a class="btnview" href="ToaTau?action=view&id=<%= dsnd.get(i).getMatoatau()%>">View</a>
                        <a class="btnedit" href="ToaTau?action=edit&id=<%= dsnd.get(i).getMatoatau() %>">Edit</a>
                    </td>
                </tr>
                <% } %>
 
            </table>
          </div>   
            </form>
            </div>         
        </div>        
    </div>          
    <% } catch(Exception ex){ response.sendRedirect("fail.jsp"); } %>
    </body>
</html>
